<?php
declare (strict_types = 1);

namespace app\middleware;

use Closure;
use think\facade\Session;
use think\response\Redirect;

class AuthAdminMiddleware
{
    /**
     * 处理请求
     * @param $request
     * @param Closure $next
     * @param $guard
     * @return Redirect|Closure
     */
    public function handle($request, Closure $next, $guard)
    {
        // 验证是否登录
        if (Session::has('aid') && Session::has('adminInfo')) {
            if (!$guard) return redirect('/admin/index');

            // TODO 验证是否授权
        } else {
            if ($guard) return redirect('/admin/login');
        }
        return $next($request);
    }
}
